package com.example.studentportrait.controller.admin;

import com.example.studentportrait.domain.ResponseResult;
import com.example.studentportrait.domain.entity.JobRecruitment;
import com.example.studentportrait.service.JobRecruitmentService;
import org.springframework.web.bind.annotation.*;
import com.example.studentportrait.utils.Pagebean;
import javax.annotation.Resource;

@RestController
@RequestMapping("/admin")
public class JobRecruitmentController {
    @Resource
    JobRecruitmentService jobRecruitmentService;

    /**
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/getAllJobRecruitment")
    public ResponseResult getAllJobRecruitment(@RequestParam("page") int page, @RequestParam("pagesize") int pagesize){
        try {
            Pagebean data= jobRecruitmentService.getAll(page,pagesize);
            return new ResponseResult<>(200,"返回成功",data);
        }
        catch (Exception e){
            return new ResponseResult<>(500,"返回失败",e);
        }
    }
    @GetMapping("/getByName")
    public ResponseResult getByName(@RequestParam("jobName") String jobName,@RequestParam("page") int page, @RequestParam("pagesize") int pagesize){
        try {
            Pagebean data= jobRecruitmentService.getByName(jobName,page,pagesize);
            return new ResponseResult<>(200,"返回成功",data);
        }
        catch (Exception e){
            return new ResponseResult<>(500,"返回失败",e);
        }
    }
    @GetMapping("/getByMajor")
    public ResponseResult getByMajor(@RequestParam("Major") String Major,@RequestParam("page") int page, @RequestParam("pagesize") int pagesize){
        try {
            Pagebean data= jobRecruitmentService.getByMajor(Major,page,pagesize);
            return new ResponseResult<>(200,"返回成功",data);
        }
        catch (Exception e){
            return new ResponseResult<>(500,"返回失败",e);
        }
    }
    @GetMapping("/getByRequired")
    public ResponseResult getByRequired(@RequestParam("Required") String Required,@RequestParam("page") int page, @RequestParam("pagesize") int pagesize){
        try {
            Pagebean data= jobRecruitmentService.getByRequired(Required,page,pagesize);
            return new ResponseResult<>(200,"返回成功",data);
        }
        catch (Exception e){
            return new ResponseResult<>(500,"返回失败",e);
        }
    }
    @PostMapping("/addJobRecruitment")
    public ResponseResult addJobRecruitment(@RequestBody JobRecruitment JobRecruitment){
        try {
            jobRecruitmentService.addJobRecruitment(JobRecruitment);
            return new ResponseResult<>(200,"新增成功");
        }
        catch (Exception e){
            return new ResponseResult<>(500,"新增失败",e);
        }
    }
    @PostMapping("/updateJobRecruitment")
    public ResponseResult updateJobRecruitment(@RequestBody JobRecruitment JobRecruitment){
        try {
            jobRecruitmentService.updateJobRecruitment(JobRecruitment);
            return new ResponseResult<>(200,"新增成功");
        }
        catch (Exception e){
            return new ResponseResult<>(500,"新增失败",e);
        }
    }


}
